import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;

public class PrintFile {

    public void PrintCSV() throws Exception {
    
            File file = new File("C:\\printtest.txt");
            InputStream is = new BufferedInputStream(new FileInputStream(file));
            
            PrintService service = PrintServiceLookup.lookupDefaultPrintService();
            DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
            
            DocPrintJob job = service.createPrintJob();
            Doc doc = new SimpleDoc(is, flavor, null);
            
            try {
                job.print(doc, null);
            }
            catch (PrintException e) {
                e.printStackTrace();
            }
            
            is.close();
            System.out.println("printing done...");
            
}
    public static void main(String[] args) throws Exception {
        PrintFile test = new PrintFile();
        test.PrintCSV();
    }
}